#delimit;
clear all;
version 13.1;
pause on;
program drop _all;
capture log close;
set more off;

/*INSERT FOLDER PATH*/
cd /;

foreach defn in strct {;

use multi_level_dataset_005_field_vars.dta, clear;
drop if ovrlp_anypos==1;
keep id nbcites_it treat age year yr srce_pmid srce_year case_code pubyear stk_srce_nslf rtrct_year subv*;


keep if subv_of_trth_`defn'==1;
drop if stk_srce_nslf==.;
bysort id (year): gen stk_nslf=sum(nbcites_it);
keep if year==rtrct_year | year==2011;
bysort id (year): gen delta_stk=stk_nslf[_N]-stk_nslf[1];
bysort id (year): gen delta_stk_srce=stk_srce_nslf[_N]-stk_srce_nslf[1];
bysort id (year): gen delta_lnstk=ln(1+stk_nslf[_N])-ln(1+stk_nslf[1]);
bysort id (year): gen delta_lnstk_srce=ln(1+stk_srce_nslf[_N])-ln(1+stk_srce_nslf[1]);
keep if year==rtrct_year;
collapse (mean) delta_lnstk delta_lnstk_srce delta_stk_srce delta_stk case_code rtrct_year srce_year, by(srce_pmid);

twoway (lfitci delta_lnstk delta_lnstk_srce if delta_lnstk_srce<3, clwidth(medium) alwidth(none) fintensity(inten50) estopts(vce(cluster case_code)))
|| scatter delta_lnstk delta_lnstk_srce if delta_lnstk_srce<3, msize(vsmall) mcolor(red) jitter(5) ytitle("Post-retraction  {bf:{&Delta}}Log(cites){subscript:related}" " ") xtitle(" " "Post-retraction  {bf:{&Delta}}Log(cites){subscript:retracted}") xlabel(0(0.50)3, format(%15.2f) labsize(small)) ylabel(0(0.5)2.5, format(%15.2f) angle(horizontal) labsize(small)) legend(off) saving(graphs/scatter_sclng_`defn'.gph, replace);

};